package ca.swank.hq;

import ca.swank.hardquor.*;

public class hqBoardSquare implements Cloneable
{

  private int[] adjacent;

  private int x;
  private int y;

  private int occupant;

  public hqBoardSquare(int x, int y, int above, int right, int below, int left)
  {

    this.x = x;
    this.y = y;

	adjacent = new int[hqBoard.DIR_TOTAL];
    adjacent[hqBoard.DIR_ABOVE] = above;
    adjacent[hqBoard.DIR_RIGHT] = right;
    adjacent[hqBoard.DIR_BELOW] = below;
    adjacent[hqBoard.DIR_LEFT] = left;

    this.occupant = hqBoard.PLAYER_NONE;
  }

  public hqBoardSquare()
  {
  }

  public Object clone()
  { hqBoardSquare dolly = new hqBoardSquare();
    dolly.x = x;
    dolly.y = y;
    dolly.occupant = occupant;
    dolly.adjacent = new int[adjacent.length];
    for(int d = 0; d < adjacent.length; d++)
    { dolly.adjacent[d] = adjacent[d];
    }
    return dolly;
  }

  public int setOccupant(int newOccupant)
  { int oldOccupant = occupant;
    occupant = newOccupant;
    return oldOccupant;
  }

  public int occupant()
  { return occupant;
  }

  public int x()
  { return x;
  }

  public int y()
  { return y;
  }

  public int left()
  { return adjacent[hqBoard.DIR_LEFT];
  }

  public int right()
  { return adjacent[hqBoard.DIR_RIGHT];
  }

  public int above()
  { return adjacent[hqBoard.DIR_ABOVE];
  }

  public int below()
  { return adjacent[hqBoard.DIR_BELOW];
  }

  public int getAdjacent(int direction)
  { return adjacent[direction];
  }

  public int setAbove(int newAbove)
  { int oldAbove = adjacent[hqBoard.DIR_ABOVE];
    adjacent[hqBoard.DIR_ABOVE] = newAbove;
    return oldAbove;
  }

  public int setRight(int newRight)
  { int oldRight = adjacent[hqBoard.DIR_RIGHT];
    adjacent[hqBoard.DIR_RIGHT] = newRight;
    return oldRight;
  }

  public int setBelow(int newBelow)
  { int oldBelow = adjacent[hqBoard.DIR_BELOW];
    adjacent[hqBoard.DIR_BELOW] = newBelow;
    return oldBelow;
  }

  public int setLeft(int newLeft)
  { int oldLeft = adjacent[hqBoard.DIR_LEFT];
    adjacent[hqBoard.DIR_LEFT] = newLeft;
    return oldLeft;
  }

  public int setAdjacent(int direction, int newAdjacent)
  { int oldAdjacent = adjacent[direction];
    adjacent[direction] = newAdjacent;
    return oldAdjacent;
  }

  public String toString()
  { return "(" + x + "," + y + ")";
  }

}